#include"Queue.h"
void QueueInit(Queue * p)
{
	assert(p);
	p->head = NULL;
	p->tail = NULL;
}
void QueueDestory(Queue * p)
{
	assert(p);
	QNode* ps = p->head;
	while (ps!=NULL)
	{

		QNode* next = ps->next;
		free(ps);
		ps = next;
	}
	p->head = p->tail = NULL;

}
void QueuePush(Queue* p, QDateType x)
{
	assert(p);
	QNode* ps = (QNode*)malloc(sizeof(QNode));
	if (ps == NULL)
	{
		printf("malloc fail");
		exit(-1);
	}
	ps->date = x;
	ps->next = NULL;
	if (p->head == NULL)
	{
		p->tail = p->head = ps;
	}
	else
	{
		p->tail->next = ps;
		p->tail = ps;
	}
}
void QueuePop(Queue* p)
{
	assert(p);
	assert(p->head);
	if (p->head->next == NULL)
	{
		free(p->head);
		p->head = p->tail = NULL;
	}
	else
	{
		QNode * next = p->head->next;
		free(p->head);
		p->head = next;
	}
}
bool QueueEmpty(Queue* q)
{
	assert(q);
	return q->head == NULL;
}
size_t QueueSize(Queue *q)
{
	assert(q);
	size_t numsize = 0;
	QNode * prev = q->head;
	while (prev)
	{
		numsize++;
		QNode* next = prev->next;
		prev = next;
	}
	return numsize;
}
QDateType QueueFront(Queue *p)
{
	assert(p);
	assert(p->head);
	return p->head->date;
}
QDateType QueueBack(Queue* p)
{
	assert(p);
	assert(p->head && p->tail);
	return p->tail->date;
}